/**
 * Created by IntelliJ IDEA.
 * User: GuoDapeng
 * Date: 15/8/5
 * Time: 上午9:11
 */

//post(function () {
//    window.location = getUrl();
//});

//判断网页是否加载完成
window.onload = function () {
    document.getElementById('ip').value = localStorage.getItem('ip');
    //document.getElementById('path').value = localStorage.getItem('path');
    document.getElementById('show').innerHTML = "访问地址：" + getUrl();
};

function mySave() {
    localStorage.setItem('ip', document.getElementById('ip').value);
    //localStorage.setItem('path', document.getElementById('path').value);
    document.getElementById('show').innerHTML = "访问地址：" + getUrl();
}

function go() {
    post(function () {
        window.location = getUrl();
    });
}

function getUrl() {
    return "http://" + localStorage.getItem('ip') + "/server/frontend/serverPhone/serverPhone.html";
}

function testUrl() {
    post(function () {
        alert("能够访问");
    })
}

function post(func) {
    var xmlhttp;
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
                func();
            } else {
                alert("Problem retrieving XML data:" + xmlhttp.statusText);
            }
        }
    };
    xmlhttp.open("GET", getUrl(), true);
    xmlhttp.send();
}

function addLogTest(str) {
    var node = document.createElement("p");
    var textnode = document.createTextNode(str);
    node.appendChild(textnode);
    document.getElementById("log").appendChild(node);
}